-
Notifications
You must be signed in to change notification settings - Fork 3.5k
[tool] Change gradle-check logic to enforce alignment of java versions and a minimum (17) #10206
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
[tool] Change gradle-check logic to enforce alignment of java versions and a minimum (17) #10206
Conversation
…va version alignment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request updates the Java compatibility version to 17 across multiple Android packages and enhances the gradle-check
tool to enforce this new minimum version and ensure version alignment within build.gradle
files. The changes also include numerous formatting updates in Dart files, likely from an auto-formatter.
My review focuses on the new validation logic in gradle-check
. While the new checks are a great improvement, I've identified a potential issue in how Java versions are parsed, which could lead to incorrect validation in some edge cases. I've provided a suggestion to make the parsing more robust.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
I have an optional suggestion for restructuring; feel free to ignore it if you disagree that it's simpler.
// Some java versions have the format VERSION_1_8 but we dont need to handle those | ||
// because they are below the minimum. | ||
final RegExp javaVersionMatcher = | ||
RegExp(r'JavaVersion.VERSION_(?<javaVersion>\d+)'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than tagging this on at the end, you could restructure the earlier somewhat to avoid having multiple passes over the same file looking for the same lines different ways, which I feel like makes the code harder to follow. You could start this whole method with something like (this is freehand so is probably wrong, but should give the idea):
final Map<String, String> javaVersionValues = <String, String>{};
final RegExp javaVersionMatcher =
RegExp(r'(?<value>\w+)\s*=\s*JavaVersion.VERSION_(?<javaVersion>\d+)');
for (final String line in gradleLines) {
final RegExpMatch? match = javaVersionMatcher.firstMatch(line);
if (!_isCommented(line) && match != null) {
if (foundVersion != null) {
javaVersions[match.namedGroup('value')!] = match.namedGroup('javaVersion')!;
}
}
}
Then all of the gradleLines.any((String line) => line.contains(...)
checks above are just key checks in that map, and you can use the same map below for the version checks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Organizationally what if I pulled each check into its own method then had
_validateCompatibilityVersions(List<String> gradleLines) {
_validateTargetAndSourceFormat();
_validateOptionalKotlinOptionsFormat();
_validateHomogenousAndMinimumJava()
}
That might help with readability and make it clear when formatting cares about the values vs the structure?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you prefer the current code structure, breaking out helpers so it's not one big method SGTM.
'$indentation${minimumJavaVersionError.split('\n').join('\n$indentation')}'); | ||
return false; | ||
} | ||
if (!javaVersions.every((String element) => element == '$version')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would strongly prefer making this the first check instead of the second, since if you don't already know there's going to be a check that they all match, the check above that only the first element is the right version seems wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I can make this change :) standby
Hold review/merge until #10201 has merged.
This pr is code review feedback from #10201 (comment)
Pre-Review Checklist
[shared_preferences]
pubspec.yaml
with an appropriate new version according to the [pub versioning philosophy], or I have commented below to indicate which [version change exemption] this PR falls under[^1].CHANGELOG.md
to add a description of the change, [following repository CHANGELOG style], or I have commented below to indicate which [CHANGELOG exemption] this PR falls under[^1].///
).